package com.spirng.leetcode.day07;

public class Test112 {
    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(1, new TreeNode(2), null);
        Test112 test112 = new Test112();
        test112.hasPathSum(treeNode,1);
    }
    public boolean hasPathSum(TreeNode root, int targetSum) {
        return hasPath(root,targetSum);
    }
    public boolean hasPath(TreeNode node,int targetSum){
        if(node==null){
            return false;
        }
        if(node.left==null&&0==(targetSum-node.val)&&node.right==null){//判断当前节点是否为叶子节点并且是否和为targetSum
            return true;
        }
        if(node.left==null&&0!=(targetSum-node.val)&&node.right==null){
            return false;
        }
        boolean b = hasPath(node.left, targetSum - node.val);
        boolean b1 = hasPath(node.right, targetSum - node.val);
        return b||b1;
    }
}
